package cn.tedu.rebbimq.m2_work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        f.setVirtualHost("/ryan");

        Channel c = f.newConnection().createChannel();

        c.queueDeclare(
                "helloworld",
                true,
                false,
                false,
                null
        );

        while (true){
            System.out.println("请输入消息: ");
            String s = new Scanner(System.in).nextLine();

            c.basicPublish("",
                    "helloworld",
                    MessageProperties.PERSISTENT_TEXT_PLAIN,
                    s.getBytes());
        }

    }
}
